#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>

/*
指针都是有类型的。程序执行才能知道需要用什么类型操作内存。
int a[1]; a的值是指针，a的类型为'int *'。a[0]=1，程序能明白对4字节的空间(int)赋值为1.
short a[1]; a的值是指针，a的类型为'short *'。a[0]=1，程序能明白对2字节的空间(short)赋值为1.
int a; &a就是int类型的指针。*(&a)=1;或(&a)[0]=1;程序能明白对4字节的空间(int)赋值为1.
uint64_t *a; a的类型为'uint64_t *'。a[0]=1，程序能明白对8字节的空间(uint64_t)赋值为1.
*/

typedef unsigned char (*funcType)(unsigned char *, int);

typedef struct
{
    short v;
    uint64_t *p;
} myCheckStc;

int main(int argc, char **argv)
{
    {
        int tmpval = 0;
        // warning: initialization of ‘char *’ from incompatible pointer type ‘int *’
        // 说明tmpptr的类型是'char *'，&tmpval的类型是'int *'
        char *tmpptr = &tmpval;
        tmpptr[0] = 155;
        printf("[%s,%d]ptr[0]=%d, tmpval=%d\n", __FILE__, __LINE__, tmpptr[0], tmpval);
    }
    {
        myCheckStc tmpval;
        // initialization of ‘char *’ from incompatible pointer type ‘myCheckStc *’
        // &tmpval是'myCheckStc *'类型。
        char *tmptr = &tmpval;
    }
    {
        funcType tmpval = NULL;
        // initialization of ‘char *’ from incompatible pointer type ‘unsigned char (**)(unsigned char *, int)’
        // &tmpval是'unsigned char (**)(unsigned char *, int)'类型。
        char *tmptr = &tmpval;
    }
    {
        char tmpval[5];
        // initialization of ‘int *’ from incompatible pointer type ‘char *’ 
        // &tmpval类型：‘char *’
        int *tmptr = tmpval;
        // initialization of ‘int *’ from incompatible pointer type ‘char (*)[5]’
        // &tmpval类型：‘char (*)[5]’
        int *tmptr1 = &tmpval;
    }
    {
        int16_t tmpval = 0;
        // initialization of ‘int64_t *’ {aka ‘long int *’} from incompatible pointer type ‘int16_t *’ {aka ‘short int *’}
        int64_t *tmpptr = &tmpval;
        // 这样写可能崩溃。
        printf("[%s,%d]&val=%p,&ptr=%p\n", __FILE__, __LINE__, &tmpval, &tmpptr);

        printf("[%s,%d]debug1:val=%d,ptr=%p\n", __FILE__, __LINE__, tmpval, tmpptr);
        tmpptr[0] = 1;
        printf("[%s,%d]debug2:val=%d,ptr=%p\n", __FILE__, __LINE__, tmpval, tmpptr);
        tmpptr[0] = 2;
        printf("[%s,%d]debug3:val=%d,ptr=%p\n", __FILE__, __LINE__, tmpval, tmpptr);
    }
    return 1;
}
